﻿using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using YArchitech.Controls;
using YArchitech.DataModel;
using YArchitech.HVAC.Properties;
using YArchitech.LIB;

namespace YArchitech.HVAC
{
	public partial class SprinklerConnTypeSetForm : System.Windows.Forms.Form
	{
		public SprinklerConnTypeSetForm()
		{
			this.InitializeComponent();
			new YJKProcessTools().ShowInTaskbarChange(this);
			base.Icon = Resource.YArchitechIcon;
		}

		private void pbType1_Click(object sender, EventArgs e)
		{
			if (this.pbType1.BorderStyle == BorderStyle.FixedSingle)
			{
				this.SetPicStyle("1");
			}
		}

		private void pbType12_Click(object sender, EventArgs e)
		{
			if (this.pbType2.BorderStyle == BorderStyle.FixedSingle)
			{
				this.SetPicStyle("2");
			}
		}

		private void SetPicStyle(string style)
		{
			if (style == "1")
			{
				this.pbType1.BorderStyle = BorderStyle.Fixed3D;
				this.pbType2.BorderStyle = BorderStyle.FixedSingle;
				this.pbType1.BackColor = System.Drawing.Color.Blue;
				this.pbType2.BackColor = System.Drawing.Color.White;
				this.textBox1.Enabled = false;
				return;
			}
			if (style == "2")
			{
				this.pbType2.BorderStyle = BorderStyle.Fixed3D;
				this.pbType1.BorderStyle = BorderStyle.FixedSingle;
				this.pbType2.BackColor = System.Drawing.Color.Blue;
				this.pbType1.BackColor = System.Drawing.Color.White;
				this.textBox1.Enabled = true;
			}
		}

		private void btnCancel_Click(object sender, EventArgs e)
		{
			base.DialogResult = DialogResult.Cancel;
		}

		private void btnOk_Click(object sender, EventArgs e)
		{
			string[] array = new string[]
			{
				"",
				""
			};
			if (this.pbType1.BorderStyle == BorderStyle.Fixed3D)
			{
				this.connType = "1";
				array[0] = this.connType;
			}
			else
			{
				if (this.textBox1.Text == "")
				{
					YJKMessageBox.Information("请输入喷头与支管高差");
					return;
				}
				if (double.Parse(this.textBox1.Text) == 0.0)
				{
					YJKMessageBox.Information("高度差不能为0");
					return;
				}
				this.connType = "2";
				this.dMainBranchPipeOffset = double.Parse(this.textBox1.Text.ToString());
				array[0] = this.connType;
			}
			array[1] = this.textBox1.Text;
			this.userSetting.WriteGetSprinklerDistance(array);
			base.DialogResult = DialogResult.OK;
		}

		private void SprinklerConnTypeSetForm_Load(object sender, EventArgs e)
		{
			string[] sprinklerDistance = this.userSetting.GetSprinklerDistance();
			this.SetPicStyle(sprinklerDistance[0]);
			this.textBox1.Text = sprinklerDistance[1];
		}

		private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
		{
			if (e.KeyChar != '\b' && !char.IsDigit(e.KeyChar) && e.KeyChar != '.')
			{
				e.Handled = true;
			}
		}

		public string connType = "1";

		public double dMainBranchPipeOffset;

		private HVACUserSetting userSetting = new HVACUserSetting();
	}
}
